<style lang="scss" scoped="">
  @import "../../utils/base.scss";
    #file {
      display: none;
    }
    .ivu-table-stripe .ivu-table-body tr:nth-child(2n) td, .ivu-table-stripe .ivu-table-fixed-body tr:nth-child(2n) td {
        background-color: #ffffff;
    }
    td.ivu-table-expanded-cell {
      padding: 0px;
    }
    .myLabel{
      display: inline-block;
      padding-bottom: 5px;
    }
    .ivu-table-overflowX {
        overflow-x: hidden;
    }
    .header_title{
        height: 50px;
        line-height: 32px;
        padding-top: 9px;
        padding-bottom: 9px;
    }
    .col_paddingleft{
        padding-left:12px
    }
</style>
<template>
  <div>
    <pheader :width="'15%'">
      <template slot="left">租户管理/项目配置</template>
      <div style="text-align: right;margin-right: 32px;" slot="right">
        <input type="file" id="file" @change="importFile" />
        <!-- <strong style="font-size: 14px" v-if="this.$hasPerm('project:combine')">合并两个项目</strong>
                <i-switch v-model="showCheckbox" style="margin-right: 5px;" @on-change="clear" v-if="this.$hasPerm('project:combine')"></i-switch>
                <Button type="primary" size="small"  @click="combine()" v-if="this.$hasPerm('project:combine')">确定</Button> -->
        <Button type="primary" size="small" @click="selectFile" v-if="this.$hasPerm('projectImport')">批量导入租户信息</Button>
        <Button type="primary" size="small" @click="add()" v-if="this.$hasPerm('projectAdd')">新增</Button>
      </div>
    </pheader>
    <tabContent>
      <template slot="content">
        <Form :label-width="70" label-position="right">
            <Row class=" header_title">
            <Col span="4">
              <FormItem label="项目名称" style="margin-bottom: 0px;">
                <Input v-model="searchInfo.project" placeholder="项目名称" style="width:150px;" @on-enter="search(0)" />
              </FormItem>
            </Col>
            <Col span="4" class="col_paddingleft">
              <FormItem label="运营人员" style="margin-bottom: 0px;">
                <Input v-model="searchInfo.business" placeholder="运营人员" style="width:150px;" @on-enter="search(0)" />
              </FormItem>
            </Col>
            <Col span="4" class="col_paddingleft">
              <FormItem label="项目经理" style="margin-bottom: 0px;">
                <Input v-model="searchInfo.manager" placeholder="项目经理" style="width:150px;" @on-enter="search(0)" />
              </FormItem>
            </Col>
            <Col span="4" class="col_paddingleft">
              <FormItem label="用户名称" style="margin-bottom: 0px;">
                <Input v-model="searchInfo.user_name" placeholder="关联的用户" style="width:150px;" @on-enter="search(0)" />
              </FormItem>
            </Col>
            <Col span="2" style="text-align: center">
              <a style="position: relative;" href="javascript:void(0)" @click="setMore">{{isSearchMore?'收起>>':'更多>>'}}</a>
            </Col>
            <Col span="6" style="text-align: end">
              <Button type="primary" @click="search(0)">查询</Button>
              <Button type="primary" @click="refresh()">重置</Button>
            </Col>
          </Row>
          <Row v-if="isSearchMore" class="header_title" style="padding-top: 0px;">
            <Col span="4">
            <FormItem label="所属租户" style="margin-bottom: 0px;">
              <Input v-model="searchInfo.tenant_name" placeholder="所属租户" style="width:150px;" @on-enter="search(0)" />
            </FormItem>
            </Col>
            <Col span="4" class="col_paddingleft">
            <FormItem label="入驻位置" style="margin-bottom: 0px;">
              <Select v-model="searchInfo.position" placeholder="搜索或下拉选择" filterable clearable style="width:150px;">
                <Option v-for="item in positionList" :value="item.position" :key="item.position">{{item.label}}</Option>
              </Select>
            </FormItem>
            </Col>
            <Col span="4" class="col_paddingleft">
            <FormItem label="项目类型" style="margin-bottom: 0px;">
              <Select v-model="searchInfo.projectType" placeholder="搜索或下拉选择" filterable clearable style="width:150px;">
                <Option v-for="item in projectTypeList" :value="item.projectType" :key="item.projectType">{{item.label}}</Option>
              </Select>
            </FormItem>
            </Col>
            <Col span="4" class="col_paddingleft">
            <FormItem label="项目状态" style="margin-bottom: 0px;">
              <Select v-model="searchInfo.isWithDraw" placeholder="搜索或下拉选择" filterable clearable style="width:150px;">
                <Option v-for="item in statusList" :value="item.value" :key="item.value">{{item.label}}</Option>
              </Select>
            </FormItem>
            </Col>
          </Row>
        </Form>
        <Table border ref="selection" :columns="columns" :data="data" :loading="tableLoading">
          <template slot-scope="{row, index}" slot="action">
            <Checkbox @on-change="push(row, index)" v-bind:disabled="check(index)"></Checkbox>
          </template>
          <template slot-scope="{row, index}" slot="startTime">
            <span>{{formatDate(row.create_time)}}</span>
          </template>
          <template slot-scope="{row, index}" slot="isWithDraw">
            <span v-if="row.isWithDraw=='0'">正常</span>
            <span v-else>销户</span>
          </template>
          <template slot-scope=" { row, index }" slot="clickAction">
            <div style="display: inline-block;">
              <a v-if="$hasPerm('projectEdit') && row.isEdit==1" href="javascript:void(0)" @click="edit(index,row)">
                <div class="text_link" style="width: 50px;">
                  编辑
                </div>
              </a>
              <a v-if="$hasPerm('projectMove') && row.isEdit==1" href="javascript:void(0)" @click="deleteProject(row.id)">
                <div class="text_link" style="width: 50px;">
                  删除
                </div>
              </a>
            </div>
          </template>
        </Table>

        <div style="margin: 10px;overflow: hidden">
          <div style="float: right;">
            <Page :current="page" :total="total" show-total show-elevator show-sizer @on-change="changePage"
              @on-page-size-change="changePageSize"></Page>
          </div>
        </div>
        <Modal @on-ok="add_ok()" @on-cancel="cancel('add_menu')" v-model="add_menu.show" :mask-closable="false"
          :loading="loading" :title="add_menu.isupdate === 0 ?'新增项目':(add_menu.isupdate === 1?'编辑项目':'合并项目')" width="750">
          <Form ref="add_menu" :model="add_menu" :rules="ruleInline" label-position="left" :label-width="130">
            <Row >
              <Col span="10" >
              <FormItem label="项目名称：" prop="project">
                <Input v-model="add_menu.project" @on-change="checkProject" />
              </FormItem>
              </Col>
              <Col span="10" style="left:10%">
              <FormItem label="所属租户:" prop="tenant_id">
                <Select v-model="add_menu.tenant_id" placeholder="搜索或下拉选择" filterable>
                  <Option v-for="item in tenantList" :value="item.id" :key="item.id">{{item.tenant_name}}</Option>
                </Select>
              </FormItem>
              </Col>
            </Row>
            <Row >
              <Col span="10" >
              <FormItem label="开始时间：" prop="create_time">
                <DatePicker :options="disabledDate" v-model="add_menu.create_date" type="date" placeholder="选择开始时间"
                  format="yyyy-MM-dd" @on-change="changeCreateDate" :clearable="false"></DatePicker>
              </FormItem>
              </Col>
              <Col span="10" style="left:10%">
              <FormItem label="结束时间:" prop="end_time">
                <DatePicker :options="disabledDate" v-model="add_menu.end_date" type="date" placeholder="选择结束时间" format="yyyy-MM-dd"
                  @on-change="changeEndDate" :clearable="false"></DatePicker>
              </FormItem>
              </Col>
            </Row>
            <Row >
              <Col span="10" >
              <FormItem label="周期长短：" prop="cycle">
                <Select v-model="add_menu.cycle" filterable>
                  <Option v-for="item in cycleList" :value="item.cycle" :key="item.cycle">{{item.label}}</Option>
                </Select>
              </FormItem>
              </Col>
              <Col span="10" style="left:10%">
              <FormItem label="是否签订合同:" prop="isContract">
                <Select v-model="add_menu.isContract" filterable>
                  <Option v-for="item in isContractList" :value="item.isContract" :key="item.isContract">{{item.label}}</Option>
                </Select>
              </FormItem>
              </Col>
            </Row>
            <Row >
              <Col span="10" >
              <FormItem label="入驻位置：" prop="position">
                <Select v-model="add_menu.position" placeholder="搜索或下拉选择" filterable>
                  <Option v-for="item in positionList" :value="item.position" :key="item.position">{{item.label}}</Option>
                </Select>
              </FormItem>
              </Col>
              <Col span="10" style="left:10%">
              <FormItem label="项目类型:" prop="projectType">
                <Select v-model="add_menu.projectType" placeholder="搜索或下拉选择" filterable>
                  <Option v-for="item in projectTypeList" :value="item.projectType" :key="item.projectType">{{item.label}}</Option>
                </Select>
              </FormItem>
              </Col>
            </Row>
            <Row >
              <Col span="10" >
              <FormItem label="项目经理：" prop="manager">
                <component ref="inputSearch"  :dataList="managerList"  :checkLable="add_menu.managerId" :is="'inputSearch'"
                   :multiple="false" :isSysUser="false" @on-change="getManagerPhone"></component>
              </FormItem>
              </Col>
              <Col span="10" style="left:10%">
              <FormItem label="项目经理联系方式:">
                <Input v-model="add_menu.manager_phone" />
              </FormItem>
              </Col>
            </Row>
            <Row >
              <Col span="10" >
              <FormItem label="项目运营人员：">
                <component ref="inputSearch"  :dataList="businessList"  :checkLable="add_menu.businessId" :is="'inputSearch'"
                   :multiple="false" :isSysUser="false" @on-change="getBusiness"></component>
              </FormItem>
              </Col>
              <Col span="10" style="left:10%">
              <FormItem label="是否销户：" prop="isWithDraw">
                <Select v-model="add_menu.isWithDraw" placeholder="搜索或下拉选择" filterable @on-change="changeDraw">
                  <Option v-for="item in drawList" :value="item.value" :key="item.value">{{item.label}}</Option>
                </Select>
              </FormItem>
              </Col>
            </Row>
            <Row>
              <Col span="10" v-if="add_menu.isWithDraw==='1'">
              <FormItem label="销户时间：" :required="true">
                <DatePicker :options="disabledDate" v-model="add_menu.drawDate" type="date" placeholder="选择结束时间" format="yyyy-MM-dd"
                  @on-change="changeDrawDate" :clearable="false"></DatePicker>
              </FormItem>
              </Col>
            </Row>
            <Row>
              <Col span="10">
              <FormItem label="是否为梧桐租户：" :required="true">
                <Select v-model="add_menu.isWTtenant" filterable placeholder="是否为梧桐租户">
                  <Option v-for="(item, index) in isWTtenantList" :value="item.value" :key="index">{{item.label}}</Option>
                </Select>
              </FormItem>
              </Col>
              <Col span="10" style="left:10%">
              <FormItem label="租户唯一标识：" :required="true">
                <Input v-model="add_menu.uniqueId" />
              </FormItem>
              </Col>
            </Row>
            <Row>
              <Col>
              <FormItem label="关联用户：">
                <Select v-model="add_menu.usersId" multiple filterable remote :remote-method="remoteMethod" :loading="selectLoading"
                  style="width:520px" placeholder="请搜索用户" @on-change="changeUsers">
                  <Option v-for="(option, index) in userList" :value="option.id" :key="index">{{option.user_name}}</Option>
                </Select>
              </FormItem>
              </Col>
            </Row>
            <Row >
              <Col span="23" >
              <FormItem label="项目描述：" prop="des">
                <Input v-model="add_menu.des" type="textarea" :rows="3" style="width:97%" />
              </FormItem>
              </Col>
            </Row>
          </Form>
        </Modal>
      </template>
    </tabContent>
  </div>
</template>

<script>
  import expandRow from './project_expand.vue'
  import pheader from "../../comp_chatter/pheader"
  import Axios from 'axios'
  import ajax from "../../ajax_util"
  import inputSearch from '../../base/input_search'
  import tabContent from "../../comp_chatter/tab_content.vue"
  import untils from "../../utils/excel";

  export default {
    components: {
      expandRow,
      pheader,
      inputSearch,
      tabContent
    },

    props: {

    },
    data() {
      const validateProject = (rule, value, callback) => {
        this.project_repetition = -1;
        if (value === '') {
          callback(new Error('请输入项目名称.'));
        }
        // else if( (!this.add_menu.isupdate) || (this.add_menu.isupdate&&this.ifProject) ){
        //     for(var i=0; i<this.project_nameList.length; i++){
        //         if(value === this.project_nameList[i]){
        //             this.project_repetition=1;
        //             callback(new Error('该项目名称已存在!'));
        //         }
        //     }
        //     callback();
        // }
        else {
          callback();
        }
      };
      return {
        tableLoading: false,
        selection: '',
        ruleInline: {
          project: [{
            required: true,
            validator: validateProject,
            trigger: 'blur'
          }],
          tenant_id: [{
            required: true,
            message: '请选择配置的角色.',
            trigger: 'blur'
          }],
          // create_time:[
          //     { required: true, message: '请选择开始时间.', trigger: 'blur' }
          // ],
          // end_time:[
          //     { required: true, message: '请选择结束时间.', trigger: 'blur' }
          // ],
          cycle: [{
            required: true,
            message: '请选择周期长短.',
            trigger: 'blur'
          }],
          isContract: [{
            required: true,
            message: '请选择是否签订合同.',
            trigger: 'blur'
          }],
          position: [{
            required: true,
            message: '请选择入驻位置.',
            trigger: 'blur'
          }],
          projectType: [{
            required: true,
            message: '请选择项目类型.',
            trigger: 'blur'
          }],
          manager: [{
            required: true,
            message: '请输入项目经理.',
            trigger: 'blur'
          }],
          isWithDraw: [{
            required: true,
            message: '请选择是否销户.',
            trigger: 'change'
          }],
          des: [{
            required: true,
            message: '请输入项目描述.',
            trigger: 'blur'
          }]
        },
        // options: {
        //     disabledDate (date) {
        //         return date && date.valueOf() < Date.now() - 86400000;
        //     }
        // },
        disabledDate: {
          disabledDate(date) {
            return date && date.valueOf() > 4070880000000;
          }
        },
        add_menu: {
          show: false,
          project: "",
          tenant_id: "",
          des: "",
          create_time: 0,
          create_date: "",
          end_time: 0,
          end_date: "",
          cycle: "",
          isContract: "",
          position: "",
          projectType: "",
          managerId: 0,
          manager: "",
          manager_phone: "",
          businessId: 0,
          isWithDraw: "",
          withDrawTime: 0,
          drawDate: "",
          usersId: [],
          isupdate: 0,
          updateId: -1,
          combine01: -1,
          combine02: -1,
          isWTtenant: 1,
          uniqueId: ""
        },
        selectLoading: false,
        userList: [],
        allNameList: [],
        managerList: [],
        manager_name: 0,
        loading: true,
        data: [],
        dataPage: [],
        project_nameList: [],
        project_repetition: -1,
        tenantList: [],
        model: '',
        showCheckbox: false,
        onCheck: [],
        param: [],
        businessList: [],

        page: 1,
        pageSize: 10,
        search_param: '',
        searchInfo: {
          project: "",
          business: "",
          manager: "",
          user_name: "",
          tenant_name: "",
          position: "",
          projectType: "",
          isWithDraw: ""
        },
        total: 0,
        url_id: '0',
        cycleList: [{
            cycle: '短期',
            label: '短期'
          },
          {
            cycle: '长期',
            label: '长期'
          }
        ],
        isContractList: [{
            isContract: '是',
            label: '是'
          },
          {
            isContract: '否',
            label: '否'
          }
        ],
        positionList: [],
        projectTypeList: [],

        drawList: [{
            value: "0",
            label: "否"
          },
          {
            value: "1",
            label: "是"
          }
        ],

        statusList: [{
            value: "0",
            label: "正常"
          },
          {
            value: "1",
            label: "销户"
          }
        ],

        temp_project: "",
        ifProject: false,
        isSearchMore: false,
        isWTtenantList:[
          {
            value:1,
            label:"是"
          },
          {
            value:0,
            label:"否"
          }
        ]
      }
    },
    computed: {
      columns() {
        let columns = [];
        if (this.showCheckbox) {
          columns.push({
            title: ' ',
            key: 'select',
            width: 60,
            align: 'center',
            slot: 'action'
          })
        }
        columns.push({
          type: 'expand',
          width: 50,
          render: (h, params) => {
            return h(expandRow, {
              props: {
                row: params.row
              }
            })
          }
        });
        columns.push({
          title: '项目名称',
          key: 'project'
        });
        columns.push({
          title: '所属租户',
          key: 'tenant_name'
        });
        columns.push({
          title: '开始时间',
          key: 'create_time',
          slot: "startTime"
        });
        columns.push({
          title: '入驻位置',
          key: 'position'
        });
        columns.push({
          title: '项目类型',
          key: 'projectType'
        });
        columns.push({
          title: '状态',
          slot: 'isWithDraw',
          width: 80
        });
        if (this.$hasPerm('projectEdit') || this.$hasPerm('projectMove')) {
          columns.push({
            title: '操作',
            key: 'action',
            align: 'center',
            width: 138,
            slot: "clickAction"
          });
        }
        return columns;
      }
    },
    created: function() {
      this.positionList = this.UTILSJSON.positionList
      this.projectTypeList = this.UTILSJSON.projectTypeList
    },
    mounted() {
      this.search(0);
    },
    methods: {
      changeUsers(data) {
        //console.log("========",this.add_menu.usersId);
      },
      selectFile() {
        const el = document.getElementById("file");
        el.click();
      },
      async importFile() {
        const el = document.getElementById("file");
        const file = el.files[0];
        var that = this
        var data = await untils.importFromLocal(file, 0, "D1", 1);
        var projectList = untils.handleInfoToColKeyVal(data.body, that)
        // console.log(projectList)
        this.inportProject(projectList)
        el.value = "";
      },
      inportProject(projectList) {
        var that = this;
        var url = this.CONFIG.progress_url + '/history-import/tenant';
        ajax.post({
          url: url,
          that: that,
          data: projectList,
          success: function(data) {
            console.log("setInUser data--------->", data)
            that.$Message.success('导入成功!');
            that.search(0);
          }
        })
      },
      get_all_tenant() {
        var that = this;
        var url = this.CONFIG.url_know + '/getTenants/' + this.$store.state.user.id;

        ajax.get({
          url: url,
          that: that,
          success: function(data) {
            that.tenantList = data;
          }
        })
      },
      setMore() {
        if (this.isSearchMore) {
          this.isSearchMore = false
        } else {
          this.isSearchMore = true
        }
      },
      search(number) {
        this.tableLoading = true;

        if (number == 0) {
          this.page = 1;
        }

        var pageModel = {};
        pageModel.id = this.$store.state.user.id;
        pageModel.page = this.page;
        pageModel.pageSize = this.pageSize;
        pageModel.searchInfo = this.searchInfo;
        var that = this;
        var url = this.CONFIG.url_know + '/searchProjects';
        ajax.post({
          url: url,
          that: that,
          data: pageModel,
          success: function(data) {
            console.log("------data--------", data);
            that.total = data.total;
            that.data = data.projectList;
            that.tableLoading = false;
          }
        })
      },
      refresh() {
        this.searchInfo.project = "";
        this.searchInfo.business = "";
        this.searchInfo.manager = "";
        this.searchInfo.user_name = "";
        this.searchInfo.tenant_name = "";
        this.searchInfo.position = "";
        this.searchInfo.projectType = "";
        this.searchInfo.isWithDraw = "";
        this.isSearchMore = false;
        this.search(0);
      },
      changePage(page) {
        this.page = page;
        this.search(1);
      },
      changePageSize(pageSize) {
        this.pageSize = pageSize;
        this.search(0);
      },
      getManagerPhone(data) {
        this.add_menu.managerId = data[0].id;
        this.add_menu.manager = data[0].user_name;
        this.add_menu.manager_phone = data[0].phone;
      },
      messageWarningFn(text) {
        this.$Message.warning(text)
        setTimeout(() => {
          this.loading = false
          this.$nextTick(() => {
            this.loading = true
          });
        }, 0.1);
      },
      cancel(name) {
        this.$refs[name].resetFields();
        this.add_menu.businessId = 0;
        this.ifProject = false;
        this.project_repetition = -1;
      },
      checkProject() {
        if (this.add_menu.project == this.temp_project) {
          this.ifProject = false;
        } else {
          this.ifProject = true;
        }
      },
      add_ok() {
        var that = this;
        if (this.add_menu.project === '') {
          this.messageWarningFn('项目名称不能为空!');
          return
        }
        // else if(this.project_repetition === 1){
        //     this.messageWarningFn('该项目名称已存在!');
        //     return
        // }
        else if (this.add_menu.tenant_id < 1 || this.add_menu.tenant_id === undefined) {
          this.messageWarningFn('所属租户不能为空!');
          return
        }
        // else if( this.add_menu.create_time === 0){
        //     this.messageWarningFn('开始时间不能为空!');
        //     return
        // }else if( this.add_menu.end_time === 0){
        //     this.messageWarningFn('结束时间不能为空!');
        //     return
        // }
        else if (this.add_menu.cycle === '' || this.add_menu.cycle === undefined) {
          this.messageWarningFn('周期长短不能为空!');
          return
        } else if (this.add_menu.isContract === '' || this.add_menu.isContract === undefined) {
          this.messageWarningFn('是否签订合同不能为空!');
          return
        } else if (this.add_menu.position === '' || this.add_menu.position === undefined) {
          this.messageWarningFn('入驻位置不能为空!');
          return
        } else if (this.add_menu.projectType === '' || this.add_menu.projectType === undefined) {
          this.messageWarningFn('项目类型不能为空!');
          return
        } else if (this.add_menu.managerId == 0 || this.add_menu.managerId == undefined || this.add_menu.managerId ==
          null) {
          this.messageWarningFn('项目经理不能为空!');
          return
        } else if (this.add_menu.uniqueId === '') {
          this.messageWarningFn('租户唯一标识不能为空!');
          return
        } else if (this.add_menu.des === '') {
          this.messageWarningFn('项目描述不能为空!');
          return
        }else {
          var url = this.CONFIG.url_know + '/project'
          let project = {
            project: this.add_menu.project,
            tenant_id: this.add_menu.tenant_id,
            des: this.add_menu.des,
            create_time: this.add_menu.create_time,
            end_time: this.add_menu.end_time,
            cycle: this.add_menu.cycle,
            isContract: this.add_menu.isContract,
            position: this.add_menu.position,
            projectType: this.add_menu.projectType,
            managerId: this.add_menu.managerId,
            businessId: this.add_menu.businessId,
            isWithDraw: this.add_menu.isWithDraw,
            withDrawTime: this.add_menu.withDrawTime,
            userIdList: this.add_menu.usersId,
            ifProject: this.ifProject,
            combine01: this.add_menu.combine01,
            combine02: this.add_menu.combine02,
            uniqueId: this.add_menu.uniqueId,
            isWTtenant: this.add_menu.isWTtenant,
          };
          if (this.add_menu.isupdate == 1) { //说明是修改，不是新增
            project["id"] = this.add_menu.updateId;
            ajax.put({
              url: url,
              that: that,
              data: project,
              success: function(data) {
                //that.get_all_project();
                if (data == 0 && that.ifProject) {
                  that.messageWarningFn('该项目名称已存在!');
                } else {
                  that.$Notice.success({
                    title: '成功修改项目'
                  });
                  that.add_menu.show = false;
                  that.ifProject = false;
                  that.search(1);
                }
              }
            })
          } else if (this.add_menu.isupdate == 0) { //说明是新增
            ajax.post({
              url: url,
              that: that,
              data: project,
              success: function(data) {
                //that.get_all_project();
                if (data == 0) {
                  that.messageWarningFn('该项目名称已存在!');
                } else {
                  that.$Notice.success({
                    title: '成功新建项目'
                  });
                  that.add_menu.show = false;
                  that.ifProject = false;
                  that.search(0);
                }
              }
            })
          } else {
            var url01 = this.CONFIG.url_know + '/combine';
            project["id"] = this.add_menu.updateId;
            ajax.put({
              url: url01,
              that: that,
              data: project,
              success: function(data) {
                //that.get_all_project();
                that.$Notice.success({
                  title: '成功合并项目'
                });
                that.add_menu.show = false;
                that.ifProject = false;
                that.showCheckbox = false;
              }
            })
          }
        }
      },
      add() {
        if (this.tenantList.length < 1) {
          this.get_all_tenant();
        }

        if (this.allNameList.length < 1) {
          this.getUsersName();
        }

        this.businessList = [];
        this.managerList = [];
        this.add_menu.isupdate = 0;
        this.add_menu.show = true;
        this.add_menu.project = "";
        this.add_menu.tenant_id = 0;
        this.add_menu.des = "";
        this.add_menu.uniqueId = "";
        this.add_menu.isWTtenant = 1;
        //this.add_menu.create_date=this.getYear();
        //this.add_menu.end_date=this.getNextYear();
        this.getYear();
        this.getNextYear();
        this.add_menu.cycle = "";
        this.add_menu.isContract = "";
        this.add_menu.position = "";
        this.add_menu.projectType = "";
        this.add_menu.managerId = 0;
        this.add_menu.manager = "";
        this.add_menu.manager_phone = "";
        this.add_menu.businessId = 0;
        this.add_menu.isWithDraw = "0";
        this.add_menu.withDrawTime = 0;
        this.add_menu.usersId = [];
        this.userList = [];
      },
      edit(index, row) {
        if (this.tenantList.length < 1) {
          this.get_all_tenant();
        }

        if (this.allNameList.length < 1) {
          this.getUsersName();
        }

        console.log("----this.data[index]------", row);
        this.add_menu.isupdate = 1;
        this.add_menu.updateId = row.id;
        this.add_menu.show = true;
        this.add_menu.project = row.project;
        this.add_menu.tenant_id = row.tenant_id;
        this.add_menu.des = row.des;
        this.add_menu.create_time = row.create_time;
        this.add_menu.create_date = this.formatDate(row.create_time);
        this.add_menu.end_time = row.end_time;
        this.add_menu.end_date = this.formatDate(row.end_time);
        this.add_menu.cycle = row.cycle;
        this.add_menu.isContract = row.isContract;
        this.add_menu.position = row.position;
        this.add_menu.projectType = row.projectType;
        this.add_menu.managerId = row.managerId;
        this.add_menu.manager = row.manager;
        this.add_menu.manager_phone = row.manager_phone;
        this.add_menu.businessId = row.businessId;
        this.add_menu.isWithDraw = row.isWithDraw;
        this.add_menu.uniqueId = row.uniqueId;
        this.add_menu.isWTtenant = row.isWTtenant;

        this.temp_project = row.project;

        if (row.manager != null && row.manager != "" && row.manager != undefined) {
          this.managerList = [];
          var j = {};
          j.id = row.managerId;
          j.user_name = row.manager;
          this.managerList.push(j);
        }

        this.businessList = [];
        if (row.businessId > 0 && row.businessId != null && row.businessId != undefined) {
          var j = {};
          j.id = row.businessId;
          j.user_name = row.business;
          this.businessList.push(j);

          this.getBusiness(this.businessList);
        }

        let tempList = [];
        for (var i = 0; i < row.users.length; i++) {
          tempList.push(row.users[i].id);
        }
        this.add_menu.usersId = tempList;
        this.userList = row.users;

        if (row.isWithDraw === "0") {
          this.add_menu.withDrawTime = 0;
        } else {
          this.add_menu.withDrawTime = row.withDrawTime;
          this.add_menu.drawDate = this.formatDate(this.add_menu.withDrawTime);
        }

        //this.getManagerPhone(this.managerList);
      },

      getBusiness(data) {
        if (data != undefined && data != null && data.length != 0 && data[0] != undefined && data[0] != null) {
          console.log("!!!!!!!", data);
          this.add_menu.businessId = data[0].id;
        }
        console.log("--businessId------", this.add_menu.businessId, this.businessList);
      },

      deleteProject(id) {
        this.$Modal.confirm({
          title: '确定删除该项目？',
          width: '360',
          onOk: () => {
            this.del(id)
          }
        });
      },
      del(id) {
        sessionStorage.setItem("delete", "true");
        var that = this;
        var url = this.CONFIG.url_know + '/project/' + id;
        ajax.del({
          url: url,
          that: that,
          success: function() {
            if (that.data.length === 1 && that.page > 1) {
              that.page = that.page - 1;
            }
            that.search(1);
            that.$Notice.success({
              title: '成功删除项目'
            });
          }
        });
      },
      combine() {
        var id01 = this.param[0].id;
        var id02 = this.param[1].id;
        this.add_menu.combine01 = id01;
        this.add_menu.combine02 = id02;
        this.add_menu.isupdate = -1;
        this.add_menu.show = true;
        this.add_menu.project = this.param[0].project + "(" + this.param[1].project + ")";
        this.add_menu.tenant_id = this.param[0].tenant_id;
        this.add_menu.des = this.param[0].des + "(" + this.param[1].des + ")";

      },
      push(row, index) {
        var b = false;
        var number = -1;
        for (let i = 0; i < this.param.length; i++) {
          if (row.id === this.param[i].id) {
            b = true;
            number = i;
          }
        }
        if (b) {
          this.param.splice(number, 1);
          this.onCheck.splice(this.onCheck.indexOf(index), 1);
        } else {
          var j = {};
          j.id = row.id;
          j.project = row.project;
          j.tenant_id = row.tenant_id;
          j.des = row.des;
          this.param.push(j);
          this.onCheck.push(index);
        }
      },
      check(index) {
        if (this.onCheck.length > 1) {
          var b = true;
          for (let i = 0; i < this.onCheck.length; i++) {
            if (index === this.onCheck[i]) {
              b = false;
            }
          }
          return b;
        }
      },
      clear() {
        this.param = [];
        this.onCheck = [];
      },
      formatDate(date) {
        return this.utils.formatDate(new Date(date * 1000), "yyyy-MM-dd")
      },
      getYear() {
        var now = Date.now();
        var date = this.utils.formatDate(new Date(now), "yyyy-MM-dd");
        this.changeCreateDate(date);
        //return date;
      },
      changeCreateDate(date) {
        this.add_menu.create_date = date;
        var time = new Date(date);
        this.add_menu.create_time = (time.getTime() / 1000);
      },
      getNextYear() {
        var now = Date.now();
        var temp = new Date(now);
        var nextYear = temp.getFullYear() + 1;
        var month = temp.getMonth() + 1;
        var day = temp.getDate();
        var date = nextYear + "-" + month + "-" + day;
        this.changeEndDate(date);
        //return date;
      },
      changeEndDate(date) {
        this.add_menu.end_date = date;
        var time = new Date(date);
        this.add_menu.end_time = (time.getTime() / 1000);
      },
      changeDraw(data) {
        console.log("999999", data);
        if (data === "0") {
          this.add_menu.withDrawTime = 0;
        } else {
          var now = Date.now();
          var temp = new Date(now);
          var nextYear = temp.getFullYear() + 1;
          var month = temp.getMonth() + 1;
          var day = temp.getDate();
          var date = nextYear + "-" + month + "-" + day;
          this.add_menu.drawDate = date;
          this.changeDrawDate(this.add_menu.drawDate);
        }
      },
      changeDrawDate(date) {
        console.log("66666666666", date);
        this.add_menu.drawDate = date;
        var time = new Date(date);
        this.add_menu.withDrawTime = (time.getTime() / 1000);
      },
      getUsersName() {
        var that = this;
        var url = this.CONFIG.url_know + '/get-users';
        ajax.get({
          url: url,
          that: that,
          success: function(data) {
            that.allNameList = data;
          }
        })
      },
      remoteMethod(query) {
        console.log("===query=====", query);
        //this.userList = [];
        if (query !== '') {
          this.loading2 = true;
          setTimeout(() => {
            this.loading2 = false;
            const allNameList = this.allNameList.map(item => {
              return {
                id: item.id,
                user_name: item.user_name
              };
            });
            console.log("===222=====", query);
            this.userList = allNameList.filter(item => item.user_name.indexOf(query) > -1);
          }, 200);
        } else {
          this.userList = [];
        }
      },
    }
  }
</script>
